<?php

namespace App\Http\Controllers\api\v1;


use App\Models\Renting;
use App\severces\JwtSeverce;
use App\severces\UploadSeverce;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class UserController extends BaseController
{
    //
    public function userInfo(Request $request)
    {
        try {
            $params = $request->all();
            //验证信息
//            $params = $this->validateParams($request->all(),[
//                'nickname'=>'required',
//                'sex'=>'required',
//                'avatar'=>'required',
//            ]);

            $res = (new Renting())->userUpdate($request->uid,$params);

            if($res){
                return $this->witejson(0,null,'操作成功');
            }
        }catch (\Exception $e){
                return $this->witejson(10003,$e->getMessage(),'操作失败');
        }
    }

    /**
     * 获取新用户信息
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getUserInfo(Request $request)
    {
        try {
            $user = Renting::getUserInfoById($request->uid);

            if($user){
                return $this->witejson(0,$user,'success');
            }

        }catch (\Exception $exception){
            return $this->witejson(10003,null,$exception->getMessage());
        }

    }

    /**
     * 上传文件到云端
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function uploadFile(Request $request)
    {
        $filePath = $request->file('file')->getPathname();

        $pid =  UploadSeverce::upload($filePath);

        return $this->witejson(0,$pid,'上传成功');
    }



}
